/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/universe_observer.h"


EXTERN_C_BEGIN


void
universe_observer_nb_ships_created_handler(void* an_observable __attribute__((unused)),
					   void* observer_data,
					   void* event_data)
{
  if(event_data != NULL)
    {
      const observer_data_with_code* data
	= (observer_data_with_code*) event_data;
      if(data->code == UNIVERSE_OBSERVER_CODE_SHIP_CREATED)
	{
	  if(observer_data != NULL)
	    {
	      ++(* ((size_t*) observer_data) );
	    }
	}
    }
}

struct observer_t
universe_observer_nb_ships_created_create(size_t* counter)
{
  struct observer_t an_observer;
  an_observer.handler = universe_observer_nb_ships_created_handler;
  an_observer.data = counter;
  an_observer.data_free = NULL;
  return an_observer;
}

void
universe_observer_nb_ships_destroyed_handler(void* an_observable __attribute__((unused)),
					     void* observer_data,
					     void* event_data)
{
  if(event_data != NULL)
    {
      const observer_data_with_code* data
	= (observer_data_with_code*) event_data;
      if(data->code == UNIVERSE_OBSERVER_CODE_SHIP_DESTROYED)
	{
	  if(observer_data != NULL)
	    {
	      ++(* ((size_t*) observer_data) );
	    }
	}
    }
}

struct observer_t
universe_observer_nb_ships_destroyed_create(size_t* counter)
{
  struct observer_t an_observer;
  an_observer.handler = universe_observer_nb_ships_destroyed_handler;
  an_observer.data = counter;
  an_observer.data_free = NULL;
  return an_observer;
}


EXTERN_C_END
